#include "load_image.h"

SDL_Surface *load_image(const string &filename){
	SDL_Surface *loaded_image = NULL;
	SDL_Surface *optimized_image = NULL;

	loaded_image = IMG_Load(filename.c_str());
	if(loaded_image != NULL){
		optimized_image = SDL_DisplayFormat(loaded_image);
		SDL_FreeSurface(loaded_image);
		
		if(optimized_image != NULL){
			Uint32 colorkey = SDL_MapRGB(optimized_image->format, 255, 255, 255);
			SDL_SetColorKey(optimized_image, SDL_SRCCOLORKEY, colorkey);
		}
		else
			std :: cerr << "Error in optimized_image : " << SDL_GetError() << std :: endl;
	}
	else
		std :: cerr << "Error in loaded_image : " << IMG_GetError() << std :: endl;

	return optimized_image;
}

void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination ) {

	SDL_Rect offset;
	offset.x = x;
	offset.y = y;
	SDL_BlitSurface( source, NULL, destination, &offset );

}
